// pages/smartlife/bus_suzhou/busline/busline.js
var common = require('../../../../utils/common.js');
var needRefresh = false
Page({
  data:{
    busRouteDetail:{},
    lineDirection:'',
    guid:'',
    lineName:''
  },
  onLoad:function(options){
    var that=this
    wx.setNavigationBarTitle({
      title: options.lineName
    })
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration:10000
    })
    that.setData({
      lineDirection:options.lineDirection.replace('->','→'),
      guid:options.guid,
      lineName:options.lineName
    })
    wx.request({
        url: common.trafficUrl()+'busRouteDetail',
        data: {
            city:'suzhou',
            guid:options.guid
        },
        // header: {}, // 设置请求的 header
        success: function(res){
          if(res.data.errorCode==0){
            var busRouteDetail = res.data.data
            // console.log(busRouteDetail)
            that.setData({
              busRouteDetail:busRouteDetail
            })
          }else{
              
          }
          wx.hideToast()
        }
      })
  },
  onShareAppMessage: function () {
    var that = this
    return {
      title: that.data.lineName+'：'+that.data.lineDirection,
      path: '/pages/smartlife/bus_suzhou/busline/busline?guid='+that.data.guid+'&lineName='+that.data.lineName+'&lineDirection='+that.data.lineDirection
    }
  },
  onShow:function(){
    if(needRefresh){
    this.refresh() 
    }
  },
  onHide:function(){
    needRefresh = true
  },
  refresh:function(){
    var that=this
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration:10000
    })
    wx.request({
      url: common.trafficUrl()+'busRouteDetail',
      data: {
          city:'suzhou',
          guid:that.data.guid
      },
      // header: {}, // 设置请求的 header
      success: function(res){
        if(res.data.errorCode==0){
          var busRouteDetail = res.data.data
          that.setData({
            busRouteDetail:busRouteDetail
          })
        }else{
            
        }
        wx.hideToast()
      }
    })
  },
  mapClick:function(e){
    var that=this
    // wx.navigateTo({
    //   url: '/pages/smartlife/bus_suzhou/busline/buslinemap/buslinemap?guid='+that.data.guid+'&lineName='+that.data.lineName
    // })
  },
  stationClick:function(e){
    var that=this
    var index = e.currentTarget.dataset.index
    console.log(index)
    wx.navigateTo({
      url: '/pages/smartlife/bus_suzhou/station/station?noteGuid='+that.data.busRouteDetail.StandInfo[index].SCode+'&name='+that.data.busRouteDetail.StandInfo[index].SName
    })
  }
})